﻿/*
 * SpatialDbConnection
 * 
 * initial implementation : 20.9.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
//using Petra.Gis.DataServices;

namespace Petra.Gis.DataServices
{
  /// <summary>
  /// abstract template for any tabular style based spatial data storage
  /// note <c>Extension</c> collection, use it as Unbounded collection of any property that users might need
  /// </summary>
  public abstract partial class SpatialDbConnection : DbConnection
  {

    public Dictionary<string, object> Extensions = new Dictionary<string, object>();


    /// <summary>
    /// xaml constr.
    /// </summary>
    public SpatialDbConnection(){}




    public SpatialDbConnection(string connectionString)
      : this(){}





    //public override void Open()
    //{
    //  _sqlConnection.Open();
    //}




    //public override void Close()
    //{
    //  _sqlConnection.Close();
    //}



    //protected override DbCommand CreateDbCommand()
    //{
    //  return this.CreateCommand();
    //}



    //public abstract SpatialDbCommand CreateCommand();



    protected string _connName = "";


    public string Name
    {
      get { return _connName; }
      set 
      {
        if (value == null)
          throw new ArgumentException("connection name cant be null, please supply valid (not null) name");

        _connName = value; 
      }
    }




    //public override string DataSource
    //{
    //  get { return _sqlConnection.DataSource; }
    //}



    //public override string Database
    //{
    //  get { return _sqlConnection.Database; }
    //}



    //public override void ChangeDatabase(string databaseName)
    //{
    //  _sqlConnection.ChangeDatabase(databaseName);
    //}



    //protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
    //{
    //  return this.BeginTransaction();
    //}




    //public System.Data.SqlClient.SqlTransaction BeginTransaction()
    //{
    //  return _sqlConnection.BeginTransaction();
    //}




    //public override string ServerVersion
    //{
    //  get { return _sqlConnection.ServerVersion; }
    //}




    protected ConnectionState _xstate;
    
    
    /// <summary>
    /// xaml helper that serializes and recovers current connection state
    /// when connection was xaml serialized as open then this property must handle reopen after
    /// deserialize
    /// </summary>
    //public abstract ConnectionState XState { get; set; }
    public ConnectionState XState 
    {
      get { return _xstate; }
      set { _xstate = value; }
    }




    public bool EqualParams(SpatialDbConnection anotherConn)
    {
      if (!(anotherConn is SpatialDbConnection))
        return false;

      return this.GetType() == anotherConn.GetType() &&
             this.Name == anotherConn.Name &&
             this.ConnectionString == anotherConn.ConnectionString;
    }



  }
}
